package com.hdy.web.utils;

import com.hdy.web.pojo.Comment;

public class Sort {


    public Sort()
    {
    }

    public static Comment[] sortComment(Comment[] list)
    {
        merge(0, list.length - 1, list);
        return list;
    }

    private static void merge(int low, int high, Comment[] list)
    {
        int mid = (low + high) / 2;
        if(low < high)
        {
            merge(low, mid, list);
            merge(mid + 1, high, list);
            mergeSort(low, mid, high, list);
        }
    }

    private static void mergeSort(int low, int mid, int high, Comment[] list)
    {
        Comment[] temp=new Comment[100];
        int i = low;
        int j = mid + 1;
        int k = 0;
        while(i <= mid && j <= high)
            if(list[i].getTime().getTime() <= list[j].getTime().getTime())
                temp[k++]=list[i++];
            else
                temp[k++]=list[j++];
        while(i <= mid)
            temp[k++]=list[i++];
        while(j <= high)
            temp[k++]=list[j++];
        for(int z = 0; z < k; z++)
            list[low+z]=temp[z];
    }
}
